package com.jg.controller;

import com.jg.dto.ProductParam;
import com.jg.entity.Products;
import com.jg.service.ProductService;
import com.jg.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.List;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/6/24 下午2:54
 */
@RestController
@RequestMapping("/product")
@CrossOrigin
public class ProductController {
    @Autowired
    ProductService productService;

    @RequestMapping("/list")
    public List<Products> list(@RequestBody ProductParam productParam) {
        return productService.list(productParam);
    }

    @RequestMapping("/add")
    public String add(@RequestBody Products products) {
        return productService.add(products);
    }

    @RequestMapping("/detail")
    public Products detail(Integer productId) {
        return productService.detail(productId);
    }

    @RequestMapping("/update")
    public String update(@RequestBody Products products) {
        return productService.update(products);
    }


    @RequestMapping("/delete")
    public String delete(Integer productId) {
        return productService.delete(productId);
    }

    @RequestMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile file) {
        System.out.println("上传图片");
        return FileUtil.upload(file);
    }
}
